package com.skp.shaphan.menus;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JDialog;
import javax.swing.JMenuItem;

import com.skp.shaphan.ui.dialogs.ConnectionDialog;
import com.skp.shaphan.ui.dialogs.JavaFXConnectionDialog;

/**
 * Displays the connection dialog to connect to a database
 * @author Stephen Phillips
 *
 */
public class ConnectionConnectMenuItem extends JMenuItem implements ActionListener {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -5036995157422549554L;
	
	/* This is just for testing -- let me try out a different kind of dialog */
	private int dialogType;
	public static int JAVAFX_DIALOG_TYPE = 1;
	public static int SWING_DIALOG_TYPE = 2;

	/**
	 * Creates a basic menu item
	 */
	public ConnectionConnectMenuItem(int dialogType) {
		super();
		this.dialogType = dialogType;
		if(dialogType == JAVAFX_DIALOG_TYPE) {
			this.setMnemonic('C');
			this.setText("JavaFX Connect");
		} else {
			this.setMnemonic('J');
			this.setText("Connect");
		}
		
		this.addActionListener(this);
	}

	/**
	 * launches the connection dialog
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		JDialog dialog;
		if(dialogType == JAVAFX_DIALOG_TYPE) {
			dialog = new JavaFXConnectionDialog();
		} else {
			dialog = new ConnectionDialog();
		}
		dialog.setVisible(true);
	}
}
